//
//  CTCArticleListCell.m
//  ConsultantVersion
//
//  Created by 小龙 on 2017/4/10.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "CTCArticleListCell.h"
#import "CTCArticleModel.h"
#import "EdgeInsetsLabel.h"
#import "UIColor+RandomColorArray.h"

@interface CTCArticleListCell()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet EdgeInsetsLabel *levelLabel;
@property (weak, nonatomic) IBOutlet EdgeInsetsLabel *secondLevelLabel;
@property (weak, nonatomic) IBOutlet EdgeInsetsLabel *thirdLevelLabel;

@property (weak, nonatomic) IBOutlet UILabel *contentlabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *commentNumberLabel;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;


@end
@implementation CTCArticleListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



-(void)setArticleModel:(CTCArticleModel *)articleModel
{
    _articleModel = articleModel;
    [SDWebImageTool imageView:self.headImageView imageName:articleModel.headImg placeHolder:@"default-head" showProgress:NO];
    self.nameLabel.text = articleModel.cname;
    self.companyLabel.text = articleModel.fname;
    self.titleLabel.text = articleModel.title;
    self.contentlabel.text = articleModel.content;
    self.dateLabel.text = [NSDate stringFromTimestamp:articleModel.createDate];
    NSString *str = [NSString stringWithFormat:@"评论：%ld",(long)articleModel.discussNum];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str];
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:10.0f]
                    range:NSMakeRange(3, str.length-3)];
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:[UIColor blackColor]
                    range:NSMakeRange(0, 3)];
    
    self.commentNumberLabel.attributedText = attrStr;
    
    if ([articleModel.position isBlank]) {
        self.levelLabel.hidden = YES;
        self.secondLevelLabel.hidden  = YES;
        self.thirdLevelLabel.hidden = YES;
        
    } else {
        NSArray *positionArr = [articleModel.position componentsSeparatedByString:@" "];
        NSArray *arr = @[HEXCOLOR(0xf3913a), HEXCOLOR(0x00ae31), HEXCOLOR(0x3a8af3)];
        NSArray  *randomColorArr = [UIColor  randomColorWithColorArray:arr];
        switch (positionArr.count) {
            case 0:{
                self.levelLabel.hidden = YES;
                self.secondLevelLabel.hidden  = YES;
                self.thirdLevelLabel.hidden = YES;
                break;
            }
                
            case 1:{
                self.levelLabel.hidden = NO;
                self.levelLabel.text = articleModel.position;
                self.levelLabel.backgroundColor = [randomColorArr firstObject];
                
                self.secondLevelLabel.hidden  = YES;
                self.thirdLevelLabel.hidden = YES;
                break;
            }
                
                
            case 2:{
                self.levelLabel.hidden = NO;
                self.levelLabel.text = [positionArr firstObject];
                
                self.secondLevelLabel.hidden = NO;
                self.secondLevelLabel.text = [positionArr lastObject];
                
                self.thirdLevelLabel.hidden = YES;
                
                self.levelLabel.backgroundColor = [randomColorArr firstObject];
                self.secondLevelLabel.backgroundColor =randomColorArr[1];
                
                break;
            }
                
            default:{
                self.levelLabel.hidden = NO;
                self.levelLabel.text = [positionArr firstObject];
                
                self.secondLevelLabel.hidden = NO;
                self.secondLevelLabel.text =positionArr[1];
                
                self.thirdLevelLabel.hidden = NO;
                self.thirdLevelLabel.text = [positionArr lastObject];
                
                
                self.levelLabel.backgroundColor = [randomColorArr firstObject];
                self.secondLevelLabel.backgroundColor =randomColorArr[1];
                self.thirdLevelLabel.backgroundColor = [randomColorArr lastObject];
                
                break;
            }
        }
    }
    

}

@end
